package com.hmall.gateway.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.annotation.Order;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 全局过滤器    无需配置直接生效
 */
@Order(0)
//@Component
@Slf4j
public class MyGlobalFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // 放行
        return chain.filter(exchange);

        // 拦截
        //ServerHttpResponse response = exchange.getResponse();
        //response.setRawStatusCode(HttpStatus.SC_UNAUTHORIZED);
        //log.info("拦截请求{}",response);
        //return response.setComplete();
    }
}
